package com.ycx.ycxmybatismanagement.controller;

import com.ycx.ycxmybatismanagement.dto.ClazzDTO;
import com.ycx.ycxmybatismanagement.dto.ClazzsListDTO;
import com.ycx.ycxmybatismanagement.pojo.PageBean;
import com.ycx.ycxmybatismanagement.pojo.Result;
import com.ycx.ycxmybatismanagement.service.ClazzsService;
import com.ycx.ycxmybatismanagement.vo.ClazzsListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;

    /**
     * 班级分页
     * @param clazzsListDTO
     * @return
     */
    @GetMapping
    public Result<PageBean<ClazzsListVO>> clazzsPageList(ClazzsListDTO clazzsListDTO){
        PageBean<ClazzsListVO> clazzsPageList = clazzsService.clazzsPageList(clazzsListDTO);
        return Result.success(clazzsPageList);
    }

    /**
     * 班级删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result deleteClazzById(@PathVariable("id")Integer id){
        clazzsService.deleteClazzById(id);
        return Result.success();
    }

    /**
     * 班级添加
     * @param clazzDTO
     * @return
     */
    @PostMapping
    public Result addClazz(@RequestBody ClazzDTO clazzDTO){
        clazzsService.addClazz(clazzDTO);
        return Result.success();
    }
    @GetMapping("{id}")
    public Result<ClazzsListVO> selectClazzById(@PathVariable("id")Integer id){
        ClazzsListVO  clazz = clazzsService.selectClazzById(id);
        return Result.success(clazz);
    }

    /**
     * 修改
     * @param clazzDTO
     * @return
     */
    @PutMapping
    public Result updateClazz(@RequestBody ClazzDTO clazzDTO){
        clazzsService.updateClazz(clazzDTO);
        return Result.success();
    }

    /**
     * 查询所有班级
     * @return
     */
    @GetMapping("/list")
    public Result<List<ClazzsListVO>> selectClazzList(){
        List<ClazzsListVO> clazzList = clazzsService.selectClazzList();
        return  Result.success(clazzList);
    }

}
